using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_Login : HoWave_Root, IRequiresSessionState
{
	protected TextBox AdminUserName;
	protected TextBox AdminPassword;
	protected TextBox CheckCode;
	protected Button LoginSubmit;
	protected Label err_tips;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	private void AutoNoSaler()
	{
		try
		{
			this.conn.Execute("update HLShop_Product set EnableSale=0  where EndDate <= getdate()");
		}
		catch
		{
		}
	}
	protected void LoginSubmit_Click1(object sender, EventArgs e)
	{
		this.AutoNoSaler();
		OnlineAdmin onlineAdmin = new OnlineAdmin();
		string text = "";
		if (!(this.AdminUserName.Text == "") && !(this.AdminPassword.Text == ""))
		{
			if (this.CheckValidateCode(this.CheckCode.Text))
			{
				string name = base.Server.HtmlEncode(this.AdminUserName.Text);
				string pwd = this.Md5(base.Server.HtmlEncode(this.AdminPassword.Text));
				if (onlineAdmin.LoginAdmin(name, pwd))
				{
					LogBll logBll = new LogBll(this.conn);
					try
					{
						this.conn.Execute("Update HL_Admin Set LoginTimes=LoginTimes+1,LastLogin=LoginDate,LastLoginIP=LoginIP Where Admin_ID=" + onlineAdmin.AdminID);
						IDbDataParameter[] parameters = new IDbDataParameter[]
						{
							this.conn.CreateParameter("@LoginDate", DbType.DateTime, DateTime.Now),
							this.conn.CreateParameter("@LoginIP", DbType.String, Fetch.UserIp)
						};
						this.conn.Execute("Update HL_Admin Set LoginDate = @LoginDate, LoginIP = @LoginIP Where Admin_ID=" + onlineAdmin.AdminID, parameters);
					}
					catch (Exception ex)
					{
						base.Response.Write(ex.Message.ToString());
						onlineAdmin.LoginOut();
						logBll.AddLog("Login", Fetch.CurrentUrl, ex.Message.ToString(), DateTime.Now, onlineAdmin.AdminName, Fetch.UserIp, Fetch.webDomain, 1, "Login");
						base.Response.End();
					}
					logBll.AddLog("Login", Fetch.CurrentUrl, Language.GetAdminMsg("Login/LoginOK"), DateTime.Now, onlineAdmin.AdminName, Fetch.UserIp, Fetch.webDomain, 0, "Login");
					if (StaticFun.IsNeedCheckIdentifyRegCode && !Certify.CheckIdentifyRegCode())
					{
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('您的程序未通过官方验证，请联系我们！');location.href='admin_index.aspx';</script>", false);
					}
					else
					{
						base.Response.Redirect("admin_index.aspx");
					}
				}
				else
				{
					text = onlineAdmin.ErrStr;
					LogBll logBll = new LogBll(this.conn);
					logBll.AddLog("Login", Fetch.CurrentUrl, text, DateTime.Now, onlineAdmin.AdminName, Fetch.UserIp, Fetch.webDomain, 1, "Login");
				}
			}
			else
			{
				text = Language.GetAdminMsg("Login/CodeErr");
			}
			this.err_tips.Text = text;
		}
	}
}
